//
//  SISSImportantTakeLookRecordViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/9/7.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSImportantTakeLookRecordViewController.h"
#import "AttributedLabel.h"
#import "SISSImportantHouseTakeLookRecordCell.h"
#import "SISSImportantPassengerTakeLookRecordCell.h"
#import "SISSUploadSuccessViewController.h"

@interface SISSImportantTakeLookRecordViewController ()

/* label */
@property (weak, nonatomic) AttributedLabel *label;

/* confirmButton */
@property (weak, nonatomic) UIButton *confirmButton;

@end

@implementation SISSImportantTakeLookRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选择看房记录";
    
    
}

#pragma mark - 点击发起交易按钮
- (void)confirmButtonDidClick:(UIButton *)button {
    
    NSLog(@"发起交易");
    [self confirmButtonDidClickAction];
}


- (void)confirmButtonDidClickAction {
    SISSUploadSuccessViewController *vc = [[SISSUploadSuccessViewController alloc] init];
    vc.tipStr = @"交易意向已锁定,请尽快完成合同签署";
    vc.title = @"选择交易客户";
    vc.popBackClassName = @"SISSHouseProgressViewController";
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)setIsSelectMain:(BOOL)isSelectMain {
    _isSelectMain = isSelectMain;
    
    UIColor *bgColor = isSelectMain ? MAIN_COLOR : [UIColor groupTableViewBackgroundColor];
    [self.confirmButton setBackgroundColor:bgColor];
    [self.confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.confirmButton.userInteractionEnabled = isSelectMain;
}

#pragma mark - UITableViewDelegate & UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuseID = @"reuseID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    if ( !cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
    }
    return cell;
}




#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    
    AttributedLabel *label = [AttributedLabel yyr_labelWithText:@"温馨提示：\n仅“已确认”的有效看房记录可发起交易。" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [label setFont:[UIFont boldSystemFontOfSize:16] fontColor:MAIN_TEXT_COLOR ofRange:NSMakeRange(0, 5)];
    [self.view addSubview:label];
    self.label = label;
    
    SISSBaseTableView *tableView = [[SISSBaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    // 自动行高
    tableView.estimatedRowHeight = 80;
    tableView.rowHeight = UITableViewAutomaticDimension;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableView registerClass:[SISSImportantHouseTakeLookRecordCell class] forCellReuseIdentifier:importantHouseTakeLookRecordCellReuseID];
    [tableView registerClass:[SISSImportantPassengerTakeLookRecordCell class] forCellReuseIdentifier:importantPassengerTakeLookRecordCellReuseID];
    [self.view addSubview:tableView];
    self.tableView = tableView;
    
    // 确定
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:MAIN_COLOR];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirmButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmButton];
    self.confirmButton = confirmButton;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    // 自动布局
    CGFloat margin = 10;
    WeakSelf
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(weakSelf.view).offset(margin);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.label.mas_bottom).offset(margin);
        make.left.right.equalTo(weakSelf.view);
        make.bottom.equalTo(weakSelf.confirmButton);
    }];
    
    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(4 * margin);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(weakSelf.view);
        }
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
